# archer 
# political advan, disadvan, and the demand for partisan news
# replication file

#############
# FL PAPERS #
#############

library(foreign)
flpapers <- read.csv("FL_circulations_replication.csv")
objects(flpapers)

# MAIN PAPER FIGURE 1: FL Papers
par(cex=0.6)
options(scipen=10)
plot(flpapers$gopmargpct, flpapers$didr_tplusone, main="Relationship Between Republican Vote Margin and Circulation Changes for Florida Papers", 
     xlab="Republican Vote Margin [Percentage] ", ylab="Relative Changes for R and D Papers [Percentage]", pch=26)
labels <- c(flpapers$circyr, pos=5)
text(flpapers$gopmargpct, flpapers$didr_tplusone,labels)
abline(lm(flpapers$didr_tplusone~flpapers$gopmargpct))

# ONLINE APPENDIX B: FIGURE B1 FL papers from yrs t+1 over time
par(cex=0.6)
options(scipen=10)
plot(flpapers$circyr, flpapers$didr_tplusone, pch=19, type="p", col="red", 
     ylab="Difference-in-Differences [Percentage]", xlab=" Year ", 
     main="Relative Changes in Circulation Rates: Republican vs. Democratic Papers in Florida")
lines(flpapers$circyr, flpapers$didr_tplusone, col="red", lty=1)
abline(h=0)

#############################
# ALL LOCAL PARTISAN PAPERS #
#############################

library(foreign)
circrates <- read.csv("all_circulations_replication.csv")
objects(circrates)

# Create Pct Vars
circrates$totalcircs=circrates$circsumR + circrates$circsumD + circrates$circsumI + circrates$circsumN
circrates$didrpct <- ((((circrates$circsumR-circrates$circsumRlast)-(circrates$circsumD-circrates$circsumDlast))/circrates$totalcircs)*100)
circrates$gopmargpct <- (((circrates$gopvote-circrates$demvote)/circrates$totalvotes)*100)

# MAIN PAPER FIGURE 2: relationship between GOP vote margin and relative changes for all local partisan papers
par(cex=0.6)
plot(circrates$gopmargpct[2:20], circrates$didrpct[2:20], main="Relationship Between Republican Vote Margin and Circulation Changes for Partisan Papers, 1932-2004", 
     xlab="Republican Vote Margin [Percentage] ", ylab="Relative Changes for R and D Papers [Percentage]", pch=26)
labels <- c(circrates$year[2:20])
text(circrates$gopmargpct[2:20], circrates$didrpct[2:20],labels)
abline(lm(circrates$didrpct[2:20]~circrates$gopmargpct[2:20]))

# ONLINE APPENDIX C: FIGURE C1 GOP vote margin 1932-2004
par(cex=0.6)
options(scipen=10)
plot(circrates$year[2:20], circrates$gopmargpct[2:20], pch=19, type="p", col="black", 
     ylab="Republican Vote Margin [Percentage]", xlab=" Year ", 
     main="Republican Vote Margin, 1932-2004")
lines(circrates$year[2:20], circrates$gopmargpct[2:20], col="black", lty=1)
abline(h=0)

# ONLINE APPENDIX C: FIGURE C2 graph with R and D circs over time, 1932-2004
par(cex=0.6)
options(scipen=10)
plot(circrates$year[2:20], circrates$circsumR[2:20], pch="", type="p", col="red", 
     ylab="Circulation Levels", xlab="Year ",ylim=c(10000000,30000000), 
     main="Circulation Levels Over Time")
lines(circrates$year[2:20], circrates$circsumR[2:20], col="red", lty=1)
points(circrates$year[2:20], circrates$circsumD[2:20], col="blue", pch=17)
lines(circrates$year[2:20], circrates$circsumD[2:20], col="blue", lty=2)
par(cex=.45)
legend("topleft", bty="n", c("Republican Papers", "Democratic Papers"),
       lty=c(1, 2), pch=c("",17), col=c("red", "blue"), 
       y.intersp=1.25)

# ONLINE APPENDIX C: FIGURE C3 relative changes for all local partisan papers 1932-2004
par(cex=0.6)
options(scipen=10)
plot(circrates$year[2:20], circrates$didrpct[2:20], pch=19, type="p", col="red", 
     ylab="Difference-in-Differences [Percentage]", xlab=" Year ", 
     main="Relative Changes in Circulation Rates: Republican vs. Democratic Papers")
lines(circrates$year[2:20], circrates$didrpct[2:20], col="red", lty=1)
abline(h=0)

# ONLINE APPENDIX C: FIGURE C4 proportion of cities with at least two papers
library(foreign)
numpapers <- read.dta("prop_citiespapers.dta")
objects(numpapers)

par(cex=0.6)
plot(numpapers$YEAR, numpapers$twopapers, pch=19, type="p", col="black", 
     ylab="Proportion", xlab=" Year ", 
     main="Proportion of Cities with At Least Two Papers")
lines(numpapers$YEAR, numpapers$twopapers, col="black", lty=1)
points(numpapers$YEAR, numpapers$oneDoneRpaper, pch=17, type="p", col="red")
lines(numpapers$YEAR, numpapers$oneDoneRpaper, col="red", lty=2)
legend("topright", bty="n", c("Two Papers", "One R and One D Paper"),
       lty=c(1, 2), pch=c(19, 17), col=c("black", "red"), 
       y.intersp=1.25)

# ONLINE APPENDIX D: FIGURE D1 cable news viewership 

msnbc <- c(35.45706371, 56.85071575,
            2.477183833, -4.961832061, 3.480589023, 5.821474774, -24.20537897,
            -8.387096774)

fnc <- c(2.180232558, 27.52489331, 19.01840491, 
          -10.54358013, -2.776322682, -0.161637931, -5.666486778, -0.915331808)

year <- c(1:8)
names(year)[1] <- "2007"
names(year)[2] <- "2008"
names(year)[3] <- "2009"
names(year)[4] <- "2010"
names(year)[5] <- "2011"
names(year)[6] <- "2012"
names(year)[7] <- "2013"
names(year)[8] <- "2014"

par(cex=.75)
plot(year, fnc,
     ylim=c(-50,75),
     main="Percentage Change in Median Prime-Time Cable News Viewers",
     xlab="Year", xaxt='n',
     ylab="Percent Change", col="red", pch=19)
lines(year, fnc, col="red", lty=1)
abline(h=0, col="gray", lty=2)
axis(1, at=seq(1,8, by=1), labels=FALSE)
par(cex=.7)
text(seq(1,8, by=1), par("usr")[1]-59, labels=names(year), srt=15, pos=1, xpd=TRUE)

par(cex=.75)
points(year, msnbc, pch=23, col="blue")
lines(year, msnbc, col="blue", lty=4)

par(cex=.5)
legend(x=6.76,y=76.4, bty="n", c("Fox News", "MSNBC"), pch=c(19,23),lty=c(1,4), col=c("red", "blue"))
segments(6.5,60,6.5,105)
segments(6.5,60,15,60)
